/*
 * Sketch to scan the I2C interface for available devices
 *
 */


#include <wiring.h> // for boolean and byte
#include <Wire.h>
#undef round 

byte address;
#define MAX_ADDRESS 127
#define MIN_ADDRESS 1

void setup()
{
  // Initialize the Wiring library to communicate via I2C
  // we're the master, so there's no address here.
  Wire.begin();

  // Initialize the serial interface to log data
  Serial.begin(9600);
  
  // set up to start at the first valid address.
  address=MIN_ADDRESS;
  
}

void loop()
{
  byte result=0;
  
  // start a transmission to the device
  Wire.beginTransmission(address);
  delay(2);
  // and get the results of the transmission
  result=Wire.endTransmission();
  
  // start printing the results
  Serial.print("addr ");
  Serial.print(address,DEC);
  
  if (0 == result)
  {
    Serial.println(" found");
  }
  else
  {
    Serial.print(" error #");
    Serial.println(result,DEC);
  }
  
  // and set up to do the next address
  if(++address > MAX_ADDRESS)
  {
    address = MIN_ADDRESS;
  }
  
  // delay 1/2 second between address scan
  delay(500);
}

